home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 51 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: char.vnet.net!jason
  2. From: jason@char.vnet.net (Defender of the Realm)
  3. Newsgroups: comp.lang.c++
  4. Subject: Arguments with streams
  5. Date: 1 Jan 1996 08:27:44 GMT
  6. Organization: Vnet Internet Access, Charlotte, NC - info@char.vnet.net
  7. Message-ID: <4c85u1$cga@ralph.vnet.net>
  8. NNTP-Posting-Host: char.vnet.net
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. I've got a small problem.  I'm working on a C++ library for HTML forms
  13. and wanted to add the some functionality to 'cout'  (ostream), but
  14. am stumped.
  15.  
  16. Here's what I want:
  17.  
  18.     cout << A("http://www.vnet.net") << "Vnet" << endA << endl;
  19.  
  20. ostream& endA (ostream& f)
  21.     { f << "</a>"; return f; };
  22. ostream& A(ostream& f, char *s)
  23.     { f << "<a " << s << ">"; return f; }
  24.  
  25. My problem lies with 'A'.  Is there any way to say that the first argument
  26. to the function is the ostream at the beginning of the statement without
  27. explicitly adding it (ie. cout << A(cout, "htt...") << ... << endl; works).
  28.  
  29. I've looked briefly at the way setw is implemented both in g++ and MSVC,
  30. but the code looks over my head =)
  31.  
  32. Thanks in advance to any pointers you can give.
  33.  
  34. --Jason
  35. jason@vnet.net
  36.